<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="订单号:" prop="mail">
        <el-input v-model="queryParams.mail" placeholder="请输入订单号" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="编号:" prop="id">
        <el-input v-model="queryParams.id" placeholder="请输入编号" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="昵称:" prop="nickName">
        <el-input v-model="queryParams.nickName" placeholder="请输入昵称" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="状态:" prop="status">
        <el-select v-model="queryParams.status" clearable placeholder="请选择">
          <el-option label="已完成" value="SUCCESS" />
          <el-option label="初始化" value="INIT" />
        </el-select>
      </el-form-item>
      <el-form-item label="交易时间:" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" type="daterange" clearable placeholder="日期区间选择"
          format="YYYY-MM-DD" value-format="YYYY-MM-DD" start-placeholder="开始日期" end-placeholder="结束日期" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="walletAccountList" @selection-change="handleSelectionChange">
      <el-table-column type="index" width="50" align="center" label="序号" />
      <!-- <el-table-column label="订单号" align="center" prop="" /> -->
      <el-table-column label="订单号" align="center" prop="id" show-overflow-tooltip />
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="类型" align="center" prop="typeName" />
      <el-table-column label="金额" align="center" prop="amount">
        <template #default="scope">
          <el-tag type="success" effect="dark" v-if="scope.row.amount > 0">
            {{ scope.row.amount }}
          </el-tag>
          <el-tag type="danger" effect="dark" v-else>
            {{ scope.row.amount }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <el-tag type="success" effect="dark" v-if="scope.row.status =='已完成'">
            {{ scope.row.status }}
          </el-tag>
          <el-tag type="info" effect="dark" v-else>
            {{ scope.row.status }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="交易时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成时间" align="center" prop="successTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.successTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.current" v-model:limit="queryParams.size"
      @pagination="getList" />
  </div>
</template>

<script setup name="WalletAccount">
import { listWalletAccount } from "@/api/boot/walletAccount";
import { number } from "echarts";

const { proxy } = getCurrentInstance();

const walletAccountList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    current: 1,
    size: 10,
    type: null,
    status: null,
    positionStatus: null,
    startTime: null,
    endTime: null,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询市场买卖交易记录列表 */
function getList() {
  loading.value = true;
  listWalletAccount(queryParams.value).then(response => {
    walletAccountList.value = response.data.records;
    total.value = response.data.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    type: null,
    channel: null,
    amount: null,
    balance: null,
    duration: null,
    status: null,
    positionStatus: null,
    startTime: null,
    startPrice: null,
    endTime: null,
    endPrice: null,
    lossOrGain: null,
    userNo: null
  };
  proxy.resetForm("walletAccountRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.current = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["walletAccountRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateWalletAccount(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addWalletAccount(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

getList();
// loading.value = false;
</script>
